﻿using MDK.Device.Components;

namespace MDK.Device.Devices
{
    public class Freezer
    {
        public Freezer(IPlcDevice device)
        {
            Device = device;
            InitializeComponents();
        }

        public IPlcDevice Device { get; }

        public IActuator[] DamBoards { get; private set; }

        public IActuator[] Pushrods { get; private set; }

        public ISensor[] DamBoardSensors { get; private set; }

        public ISensor[] DoorSensors { get; private set; }

        public ISwitch[] PilotLamp { get; private set; }

        public ISensor[,] CounterSensors { get; private set; }

        public IActuator Belt { get; private set; }

        public ISensor BeltCenterSensor { get; private set; }

        public ISensor BeltEndSensor { get; private set; }

        public IFreezerController FreezerController { get; set; }
        /// <summary>
        /// 警报
        /// </summary>
        public ISwitch Alert { get; set; }

        private void InitializeComponents()
        {
            DamBoards = new IActuator[6]
            {
                new DelayActuator(Device, "M244", "M245", "M246", Constants.DelayFor1),
                new DelayActuator(Device, "M248", "M249", "M250", Constants.DelayFor1),
                new DelayActuator(Device, "M252", "M253", "M254", Constants.DelayFor1),
                new DelayActuator(Device, "M256", "M257", "M258", Constants.DelayFor1),
                new DelayActuator(Device, "M260", "M261", "M262", Constants.DelayFor1),
                new DelayActuator(Device, "M264", "M265", "M266", Constants.DelayFor1)
            };
            Pushrods = new IActuator[6]
            {
                new SensorActuator(Device, "M220", "X04", "M221", "M222", "X05"),
                new SensorActuator(Device, "M224", "X12", "M225", "M226", "X13"),
                new SensorActuator(Device, "M228", "X20", "M229", "M230", "X21"),
                new SensorActuator(Device, "M232", "X26", "M233", "M234", "X27"),
                new SensorActuator(Device, "M236", "X34", "M237", "M238", "X35"),
                new SensorActuator(Device, "M240", "X42", "M241", "M242", "X43")
            };
            DamBoardSensors = new ISensor[6]
            {
                new Sensor(Device, "X44"),
                new Sensor(Device, "X45"),
                new Sensor(Device, "X46"),
                new Sensor(Device, "X47"),
                new Sensor(Device, "X50"),
                new Sensor(Device, "X51")
            };
            DoorSensors = new ISensor[6]
            {
                new Sensor(Device, "X54"),
                new Sensor(Device, "X55"),
                new Sensor(Device, "X56"),
                new Sensor(Device, "X57"),
                new Sensor(Device, "X60"),
                new Sensor(Device, "X61")
            };
            PilotLamp = new ISwitch[6]
            {
                new Switch(Device, "M32"),
                new Switch(Device, "M33"),
                new Switch(Device, "M34"),
                new Switch(Device, "M35"),
                new Switch(Device, "M36"),
                new Switch(Device, "M37")
            };
            CounterSensors = new ISensor[6, 4]
            {
                { new Sensor(Device, "X00"),new Sensor(Device, "X01"),new Sensor(Device, "X02"),new Sensor(Device, "X03") },
                { new Sensor(Device, "X06"),new Sensor(Device, "X07"),new Sensor(Device, "X10"),new Sensor(Device, "X11") },
                { new Sensor(Device, "X14"),new Sensor(Device, "X15"),new Sensor(Device, "X16"),new Sensor(Device, "X17") },
                { new Sensor(Device, "X22"),new Sensor(Device, "X23"),new Sensor(Device, "X24"),new Sensor(Device, "X25") },
                { new Sensor(Device, "X30"),new Sensor(Device, "X31"),new Sensor(Device, "X32"),new Sensor(Device, "X33") },
                { new Sensor(Device, "X36"),new Sensor(Device, "X37"),new Sensor(Device, "X40"),new Sensor(Device, "X41") },
            };
            Belt = new DelayActuator(Device, "M268", "M269", "M270");
            BeltCenterSensor = new Sensor(Device, "X52");
            BeltEndSensor = new Sensor(Device, "X53");
            FreezerController = new FreezerController(Device, "D97", "D99", "D24", "D28");
            Alert = new Switch(Device, "M20");
        }
    }
}